﻿using System.Configuration;
using CCzoomr.Configuration;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace CCzoomr.Core.Tests
{
    [TestFixture]
    public class BuildServerSectionTests
    {
        [Test]
        public void Constructor()
        {
            object configuration = null;
            configuration = ConfigurationManager.GetSection("dashboardSettings/servers");

            Assert.That(configuration, Is.Not.Null);
            Assert.That(configuration, Is.InstanceOfType(typeof(BuildServerSection)));
        }
        
        [Test]
        public void ServersProperty()
        {
            ProviderSettingsCollection settingsCollection = null;

            BuildServerSection serverConfiguration = (BuildServerSection)ConfigurationManager.GetSection("dashboardSettings/servers");

            Assert.That(serverConfiguration, Is.Not.Null);
            Assert.That(serverConfiguration, Is.InstanceOfType(typeof(BuildServerSection)));

            settingsCollection = serverConfiguration.Servers;

            Assert.That(settingsCollection, Is.Not.Null);
            Assert.That(settingsCollection, Is.Not.Empty);
            Assert.That(settingsCollection, Is.All.Not.Null);
            Assert.That(settingsCollection.Count, Is.EqualTo(3));

            ProviderSettings settings = settingsCollection["build1"];
            Assert.That(settings, Is.Not.Null);
            Assert.That(settings.Name, Is.EqualTo("build1"));
            Assert.That(settings.Type, Is.EqualTo("CCzoomr.Providers.CruiseControlNet13BuildServerProvider, CCzoomr.Providers.CruiseControlNet13, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
            Assert.That(settings.Parameters, Is.Not.Empty);
            Assert.That(settings.Parameters, Is.Not.All.Null);
            Assert.That(settings.Parameters.Count, Is.EqualTo(1));
            Assert.That(settings.Parameters.Keys[0], Is.EqualTo("url"));
            Assert.That(settings.Parameters["url"], Is.EqualTo("tcp://bld1:21234/CruiseManager.rem"));
        }
    }
}
